1
/****************************** Module Header ******************************\
2 * Module Name: SchoolLinqToSQL.svc.cs
3 * Project: CSADONETDataService
4 * Copyright (c) Microsoft Corporation.
6 * SchoolLinqToSQL.svc demonstrates the ADO.NET Data Service for Linq to SQL
7 * Data Classes. The Linq to SQL Data Class connects to the SQL Server
8 * database deployed by SQLServer2005DB. It contains data tables: Person,
9 * Course, CourseGrade, and CourseInstructor. The service also exports a
10 * service operation SearchCourses to let the client search course objects via
13 * This source is subject to the Microsoft Public License.
14 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
15 * All other rights reserved.
17 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
18 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
20 \***************************************************************************/
22 #region Using directive
24 using System
.Collections
.Generic
;
25 using System
.Data
.Services
;
27 using System
.ServiceModel
.Web
;
29 using CSADONETDataService
.LinqToSQL
;
33 namespace CSADONETDataService
35 public class SchoolLinqToSQL
: DataService
<SchoolLinqToSQLDataContext
>
37 // This method is called only once to initialize service-wide policies.
38 public static void InitializeService(IDataServiceConfiguration config
)
40 // Set rules to indicate which entity sets and service operations
41 // are visible, updatable, etc.
42 config
.UseVerboseErrors
= true;
43 config
.SetEntitySetAccessRule("*", EntitySetRights
.All
);
44 config
.SetServiceOperationAccessRule("SearchCourses",
45 ServiceOperationRights
.All
);
49 /// A service operation that searches the courses via SQL commands
50 /// and returns an IQueryable collection of Course objects
52 /// <param name="searchText">The query SQL commands</param>
53 /// <returns>An IQueryable collection contains Course objects
56 public IQueryable
<Course
> SearchCourses(string searchText
)
58 // Call DataContext.ExecuteQuery to call the search SQL commands
59 return this.CurrentDataSource
.ExecuteQuery
<Course
>(searchText
).